<?php
require_once(ROOT_ADMIN_MODELS.DS.'Models_Base.php'); 
require_once(ROOT_ADMIN_MODELS.DS.'Models_Log.php'); 
require_once(ROOT_ADMIN_MODELS.DS.'Models_Comment.php');
require_once(ROOT_LIBRARY_UTILITY.DS.'utility.php');
require_once(ROOT_ADMIN_CONTROLLERS.DS.'BaseController.php');
class Admin_CommentController extends BaseController {
	
	public function preDispatch()
	{
		parent::preDispatch();	
		if(!$this->hasPrivilege())
			$this->_redirect ("/admin/error/permission");
	}
	
	public function indexAction()
	{
		$this->view ->headTitle("UIT-News Supporter");
		try
		{
			$md=new Models_Comment();
			$from ="";$to="";
			if($this->_request->isPost())
			{
				if($_POST['fromday'] != "")
					$from = $_POST['fromday'];
				if ($_POST['today'] != "")
					$to = $_POST['today'];
			}
			$this->view->from = $from;
			$this->view->to = $to;
			$this->view->data=$md->listComment($from,$to);
		}
		catch (Exception $ex)
		{
			$this->view->errMsg = $ex->getMessage();
			Utility::log($ex->getMessage(), $ex->getFile(), $ex->getLine());
		}
	}
	
	public function statusAction()
	{
		$this->_helper->layout->disableLayout();
		$this->_helper->viewRenderer->setNorender();
		try
		{
			$md = new Models_Comment();
			$id = $_POST['id'];
			$status = $_POST['status'];
			$md->active($id, $status);
			echo "1";
			Models_Log::insert($this->view->user->id, "act_update_status_comment","id=".$id);
		}
		catch (Exception $ex)
		{
			$this->view->errMsg = $ex->getMessage();
			Utility::log($ex->getMessage(), $ex->getFile(), $ex->getLine());
			echo $ex->getMessage();
		}
	}
	public function deleteAction()
	{
		$this->_helper->layout->disableLayout();
		$this->_helper->viewRenderer->setNorender();
		try
		{
			$md = new Models_Comment();
			$id = $_POST['id'];
			$md->_delete($id);
			echo "1";
			Models_Log::insert($this->view->user->id, "act_delete_comment","id=".$id);
		}
		catch (Exception $ex)
		{
			$this->view->errMsg = $ex->getMessage();
			Utility::log($ex->getMessage(), $ex->getFile(), $ex->getLine());
		}
	} 
}
	